$(function () {

	function _operation_field_formatter(cellValue , options , rowData){
		var mode = 'view';
		var buttons = [];
		var id = rowData['id'];
		buttons.push('<div class="grid-operation-button">')

		if(mode == 'view') {
			buttons.push(str_format('<a class="label label-info" target="_blank" href="info.html?id={0}">查看</a>',rowData['id']));
		}
		if(mode == 'modify') {
			buttons.push(str_format('<a class="label label-info" onclick="T.vm.update(' + id + ',event)" href="javascript:;">修改</a>', rowData['id']));
		}
		buttons.push('</div>');
		return buttons.join("&nbsp;")
	}

    $("#jqGrid").jqGrid({
        url: baseURL + 'live/livewithdrawhistory/list',
        datatype: "json",
		postData: requestParameters,
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 80, key: true },
			{ label: '用户编号', name: 'uid', index: 'uid', width: 80 },
			{ label: '昵称', name: 'nickname', width: 80 },
			{ label: '头像', name: 'avanta', width: 80 ,formatter : set_images_formatter},
			{ label: '提现类型', name: 'type', width: 80, formatter: get_grid_column_formatter('live/livewithdrawhistory/type')},
			{ label: '提现金额', name: 'withdraw_money', width: 80 },
			{ label: '开户行', name: 'bank_name', width: 80 },
			{ label: '开户人', name: 'bank_realname', width: 80 },
			{ label: '银行卡号', name: 'bank_no', width: 100 },
			{ label: '状态', name: 'state', width: 80,formatter: get_grid_column_formatter('live/livewithdrawhistory/state')},
			{ label: '提现时间', name: 'adddate', index: 'adddate', width: 80 ,formatter : timestampForMS}
        ],
		viewrecords: true,
        height: 'auto',
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#webpage',
	data:{
		appearance : {
			showList: true,
			showControllBar : true,
			showSearchForm : true
		},
		q:{
			_keyword:''
		},
		title: null,
		idcardVerifyHistory: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.appearance.showList = false;
			vm.title = "新增";
			vm.idcardVerifyHistory = {};
		},
		update: function (targetId,event) {
			var id = targetId || getSelectedRow();
			if(id == null){
				return ;
			}
			vm.appearance.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.idcardVerifyHistory.id == null ? "base/idcardverifyhistory/save" : "base/idcardverifyhistory/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.idcardVerifyHistory),
			    success: function(r){
			    	if(r.code > 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "base/idcardverifyhistory/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code > 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "base/idcardverifyhistory/info/"+id, function(r){
                vm.idcardVerifyHistory = r.idcardVerifyHistory;
            });
		},
		reload: function (event) {
			vm.appearance.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
				postData:{'nickname': vm.q._keyword},
                page:page
            }).trigger("reloadGrid");
		}
	}
});